From 244ef5e5f9d322b1283a8d9f5e3a3744e67cb57f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 29 Aug 2005 11:28:01 +0000 Subject: [PATCH] made name parameter of babl_format_new optional --- ChangeLog | 18 +++++++ babl/babl-format.c | 98 +++++++++++++++++++++++++------------ babl/base/model-rgb.c | 10 ++-- babl/base/model-ycbcr.c | 6 +-- extensions/CIE-Lab.c | 6 +-- extensions/naive-CMYK.c | 7 +-- tests/Makefile.am | 2 + tests/float_to_u8.c | 2 - tests/grayscale_to_rgb.c | 2 - tests/rgb_to_bgr.c | 2 - tests/rgb_to_lab_to_rgb.c | 4 +- tests/rgb_to_ycbcr.c | 2 - tests/rgb_to_ycbcr_to_rgb.c | 4 +- tests/u8_to_float.c | 2 - 14 files changed, 106 insertions(+), 59 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8296a55..bc59154 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2005-08-29 Øyvind Kolås + + * babl/babl-format.c: (each_babl_format_destroy), (format_new), + (create_name), (babl_format_new): New API, name is now a key/value + pair, and if not set the name will be autogenerated. + * babl/base/model-rgb.c, + * babl/base/model-ycbcr.c, + * extensions/CIE-Lab.c, + * extensions/naive-CMYK.c, + * tests/Makefile.am, + * tests/float_to_u8.c, + * tests/grayscale_to_rgb.c, + * tests/rgb_to_bgr.c, + * tests/rgb_to_lab_to_rgb.c, + * tests/rgb_to_ycbcr.c, + * tests/rgb_to_ycbcr_to_rgb.c, + * tests/u8_to_float.c: update to new API. + 2005-08-29 Øyvind Kolås * babl/babl-db.h: Do nor warn about collision during db_insert diff --git a/babl/babl-format.c b/babl/babl-format.c index 1607a8c..e63f78e 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -28,7 +28,7 @@ static int each_babl_format_destroy (Babl *babl, - void *data) + void *data) { babl_free (babl->format.from); babl_free (babl->format.to); @@ -39,13 +39,13 @@ each_babl_format_destroy (Babl *babl, static Babl * format_new (const char *name, - int id, - int planar, - int components, - BablModel *model, - BablComponent **component, - BablSampling **sampling, - BablType **type) + int id, + int planar, + int components, + BablModel *model, + BablComponent **component, + BablSampling **sampling, + BablType **type) { Babl *babl; @@ -108,9 +108,36 @@ format_new (const char *name, return babl; } + +static char buf[512]=""; + +static const char * +create_name (BablModel *model, + int components, + BablComponent **component, + BablType **type) +{ + char *p = &buf[0]; + + sprintf (p, "%s ", model->instance.name); + p+=strlen (model->instance.name) + 1; + + while (components--) + { + sprintf (p, "(%s as %s) ", + (*component)->instance.name, + (*type)->instance.name); + p+=strlen ((*component)->instance.name) + + strlen ((*type)->instance.name ) + strlen("( as ) "); + component++; + type++; + } + return buf; +} + Babl * -babl_format_new (const char *name, - ...) +babl_format_new (void *first_arg, + ...) { va_list varg; Babl *babl; @@ -124,18 +151,13 @@ babl_format_new (const char *name, BablSampling *current_sampling = (BablSampling*) babl_sampling (1,1); BablType *current_type = (BablType*) babl_type_id (BABL_U8); - const char *arg = name; - - va_start (varg, name); + char *name = NULL; + void *arg = first_arg; + va_start (varg, first_arg); while (1) { - arg = va_arg (varg, char *); - if (!arg) - break; - - if (BABL_IS_BABL (arg)) { Babl *babl = (Babl*)arg; @@ -196,6 +218,11 @@ babl_format_new (const char *name, { id = va_arg (varg, int); } + + else if (!strcmp (arg, "name")) + { + name = va_arg (varg, char *); + } else if (!strcmp (arg, "packed")) { @@ -211,25 +238,34 @@ babl_format_new (const char *name, { babl_fatal ("unhandled argument '%s' for format '%s'", arg, name); } + + arg = va_arg (varg, char *); + if (!arg) + break; } va_end (varg); + babl = format_new (name?name:create_name (model, components, component, type), + id, + planar, components, model, + component, sampling, type); + + { + Babl *ret; + ret = db_insert (babl); - babl = format_new (name, id, - planar, components, model, - component, sampling, type); + if (ret==babl) + { + return babl; + } + else + { + each_babl_format_destroy (babl, NULL); + return ret; + } + } - - if (db_insert (babl) == babl) - { - return babl; - } - else - { - each_babl_format_destroy (babl, NULL); - return NULL; - } } BABL_CLASS_TEMPLATE (babl_format) diff --git a/babl/base/model-rgb.c b/babl/base/model-rgb.c index 73673f9..aff0c28 100644 --- a/babl/base/model-rgb.c +++ b/babl/base/model-rgb.c @@ -334,7 +334,7 @@ static void formats (void) { babl_format_new ( - "srgb", + "name", "srgb", "id", BABL_SRGB, babl_model_id (BABL_RGB_GAMMA_2_2), babl_type_id (BABL_U8), @@ -344,7 +344,7 @@ formats (void) NULL); babl_format_new ( - "srgba", + "name", "srgba", "id", BABL_SRGBA, babl_model_id (BABL_RGBA_GAMMA_2_2), babl_type_id (BABL_U8), @@ -355,7 +355,7 @@ formats (void) NULL); babl_format_new ( - "rgba-float", + "name", "rgba-float", "id", BABL_RGBA_FLOAT, babl_model_id (BABL_RGBA), babl_type_id (BABL_FLOAT), @@ -366,7 +366,7 @@ formats (void) NULL); babl_format_new ( - "rgba-double", + "name", "rgba-double", "id", BABL_RGBA_DOUBLE, babl_model_id (BABL_RGBA), babl_type_id (BABL_DOUBLE), @@ -377,7 +377,7 @@ formats (void) NULL); babl_format_new ( - "rgb-float", + "name", "rgb-float", "id", BABL_RGB_FLOAT, babl_model_id (BABL_RGB), babl_type_id (BABL_FLOAT), diff --git a/babl/base/model-ycbcr.c b/babl/base/model-ycbcr.c index 209b9de..2d81078 100644 --- a/babl/base/model-ycbcr.c +++ b/babl/base/model-ycbcr.c @@ -195,7 +195,7 @@ static void formats (void) { babl_format_new ( - "y'cbcr420", + "name", "y'cbcr420", "id", BABL_YCBCR420, "planar", babl_model_id (BABL_YCBCR), @@ -211,7 +211,7 @@ formats (void) babl_format_new ( - "y'cbcr422", + "name", "y'cbcr422", "id", BABL_YCBCR422, "planar", babl_model_id (BABL_YCBCR), @@ -226,7 +226,7 @@ formats (void) NULL); babl_format_new ( - "y'cbcr411", + "name", "y'cbcr411", "id", BABL_YCBCR411, "planar", babl_model_id (BABL_YCBCR), diff --git a/extensions/CIE-Lab.c b/extensions/CIE-Lab.c index ffa8708..0f321bd 100644 --- a/extensions/CIE-Lab.c +++ b/extensions/CIE-Lab.c @@ -254,7 +254,7 @@ static void formats (void) { babl_format_new ( - "CIE Lab float", + "name", "CIE Lab float", babl_model ("CIE Lab"), babl_type ("float"), @@ -264,7 +264,7 @@ formats (void) NULL); babl_format_new ( - "CIE Lab u8", + "name", "CIE Lab u8", babl_model ("CIE Lab"), babl_type ("CIE u8 L"), @@ -276,7 +276,7 @@ formats (void) NULL); babl_format_new ( - "cie-lab-u16", + "name", "cie-lab-u16", babl_model ("CIE Lab"), babl_type ("CIE u16 L"), diff --git a/extensions/naive-CMYK.c b/extensions/naive-CMYK.c index 90b6749..b69ce38 100644 --- a/extensions/naive-CMYK.c +++ b/extensions/naive-CMYK.c @@ -186,9 +186,10 @@ conversions (void) static void formats (void) { - babl_format_new ("CMYK float", - babl_model ("CMYK"), - babl_type ("float"), + babl_format_new ( + "name", "CMYK float", + babl_model ("CMYK"), + babl_type ("float"), babl_component ("cyan"), babl_component ("yellow"), babl_component ("magenta"), diff --git a/tests/Makefile.am b/tests/Makefile.am index f801c0b..d9c82bb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,6 +8,7 @@ TESTS = \ rgb_to_ycbcr_to_rgb \ srgb_to_lab_u8 \ sanity \ + types \ babl_class_name float_to_u8_SOURCES = float_to_u8.c @@ -20,6 +21,7 @@ rgb_to_ycbcr_SOURCES = rgb_to_ycbcr.c rgb_to_ycbcr_to_rgb_SOURCES = rgb_to_ycbcr_to_rgb.c babl_class_name_SOURCES = babl_class_name.c sanity_SOURCES = sanity.c +types_SOURCES = types.c AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl diff --git a/tests/float_to_u8.c b/tests/float_to_u8.c index 038bd67..3d10222 100644 --- a/tests/float_to_u8.c +++ b/tests/float_to_u8.c @@ -53,14 +53,12 @@ test_float_to_rgb_u8 (void) fish = babl_fish ( babl_format_new ( - "foo", babl_model ("Y"), babl_type ("float"), babl_component ("Y"), NULL ), babl_format_new ( - "bar", babl_model ("Y"), babl_type ("u8"), babl_component ("Y"), diff --git a/tests/grayscale_to_rgb.c b/tests/grayscale_to_rgb.c index ad896da..cc2c48e 100644 --- a/tests/grayscale_to_rgb.c +++ b/tests/grayscale_to_rgb.c @@ -39,14 +39,12 @@ test (void) fish = babl_fish ( babl_format_new ( - "foo", babl_model ("Y"), babl_type ("float"), babl_component ("Y"), NULL ), babl_format_new ( - "bar", babl_model ("RGB"), babl_type ("float"), babl_component ("R"), diff --git a/tests/rgb_to_bgr.c b/tests/rgb_to_bgr.c index 1f47bf0..2f0d395 100644 --- a/tests/rgb_to_bgr.c +++ b/tests/rgb_to_bgr.c @@ -46,7 +46,6 @@ test (void) fish = babl_fish ( babl_format_new ( - "foo", babl_model ("RGB"), babl_type ("u8"), babl_component ("R"), @@ -55,7 +54,6 @@ test (void) NULL ), babl_format_new ( - "bar", babl_model ("RGB"), babl_type ("u8"), babl_component ("B"), diff --git a/tests/rgb_to_lab_to_rgb.c b/tests/rgb_to_lab_to_rgb.c index 6a1e6fe..19a6ca6 100644 --- a/tests/rgb_to_lab_to_rgb.c +++ b/tests/rgb_to_lab_to_rgb.c @@ -76,7 +76,7 @@ test (void) fish = babl_fish ( babl_format_new ( - "foo", + "name", "foo", babl_model ("RGB"), babl_type ("float"), babl_component ("R"), @@ -85,7 +85,7 @@ test (void) NULL ), babl_format_new ( - "bar", + "name", "bar", babl_model ("CIE Lab"), babl_type ("float"), babl_component ("CIE L"), diff --git a/tests/rgb_to_ycbcr.c b/tests/rgb_to_ycbcr.c index d06b72f..e07d1b0 100644 --- a/tests/rgb_to_ycbcr.c +++ b/tests/rgb_to_ycbcr.c @@ -53,7 +53,6 @@ test (void) fish = babl_fish ( babl_format_new ( - "foo", babl_model ("RGB"), babl_type ("float"), babl_component ("R"), @@ -62,7 +61,6 @@ test (void) NULL ), babl_format_new ( - "bar", babl_model ("Y'CbCr"), babl_type ("float"), babl_component ("Y'"), diff --git a/tests/rgb_to_ycbcr_to_rgb.c b/tests/rgb_to_ycbcr_to_rgb.c index 0fbdf44..117aba0 100644 --- a/tests/rgb_to_ycbcr_to_rgb.c +++ b/tests/rgb_to_ycbcr_to_rgb.c @@ -45,7 +45,7 @@ test (void) fish = babl_fish ( babl_format_new ( - "foo", + "name", "foo", babl_model ("RGB"), babl_type ("float"), babl_component ("R"), @@ -54,7 +54,7 @@ test (void) NULL ), babl_format_new ( - "bar", + "name", "bar", babl_model ("Y'CbCr"), babl_type ("float"), babl_component ("Y'"), diff --git a/tests/u8_to_float.c b/tests/u8_to_float.c index 6249609..d49c812 100644 --- a/tests/u8_to_float.c +++ b/tests/u8_to_float.c @@ -38,14 +38,12 @@ test (void) fish = babl_fish ( babl_format_new ( - "foo", babl_model ("Y"), babl_type ("u8"), babl_component ("Y"), NULL ), babl_format_new ( - "bar", babl_model ("Y"), babl_type ("float"), babl_component ("Y"), -- 2.30.2